﻿Public Class clsTaskStep

    Public Function SelectTaskStep() As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM agv.task_step order by sys_id asc"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1)
        If IsNothing(dt) Then
            SelectTaskStep = New DataTable
        Else
            SelectTaskStep = dt
        End If
    End Function

    Public Function SelectTaskStepById(id As String) As DataTable
        Dim szSql As String = ""
        szSql &= "SELECT * FROM agv.task_step where sys_id = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, id)
        If IsNothing(dt) Then
            SelectTaskStepById = New DataTable
        Else
            SelectTaskStepById = dt
        End If
    End Function

    Public Function updateTaskStep(state As String, state_task As String, id As String, task_id As String) As Integer
        Dim szSql As String = String.Empty
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            '更新新任务步骤状态
            szSql &= "update agv.task_step set status = ?,update_time = (SELECT CURRENT_TIMESTAMP(6))"
            szSql &= "where sys_id = ?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, state, id)
            '插入state表状态
            szSql = String.Empty
            szSql &= "insert into agv.task_step_state(task_step_id,state,update_time) values ('" & id & "','" & state & "',(SELECT CURRENT_TIMESTAMP(6)))"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1)
            '更新任务表状态
            szSql = String.Empty
            szSql &= "update agv.task set status = ?,update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= "where sys_id=?"
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, state_task, task_id)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        Finally
            DBacs.RollbackTransaction()
        End Try

        Return rtn
    End Function

End Class
